import Mock from 'mockjs'
import { param2Obj } from '../utls/utilsDemo'
var List = []
for (var i = 0; i < 30; i++) {
    List.push({
        id: Mock.mock('@guid()'),
        ordernum: Mock.mock('@id()'), //订单编号
        weixin: Mock.mock('@first()'), //用户微信
        tel: Mock.mock({
            'regexp': /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}/
        }), //手机号 
        classname: Mock.mock('@integer(0, 3)'), //课程名称
        money: Mock.mock('@natural(100, 2000)'), //订单余额
        type: Mock.mock('@integer(2, 6)'),
        submittime: Mock.mock('@datetime("yyyy-MM-dd HH:mm")') //提交时间
    })
}
export default {

    //删除
    deleteData: (config) => {
        var id = JSON.parse(config.body).id;
        List.forEach((item, index) => {
            if (item.id == id) {
                List.splice(index, 1);
            }
        })
        return {
            code: 200,
            msg: '删除成功',
            data: null
        }
    },

    //批量删除
    batchdeleteData: (config) => {
        var {
            ids
        } = JSON.parse(config.body)
        var newArr = List.filter(item => ids.indexOf(item.id) == -1)
        List = newArr;
        return {
            code: 200,
            msg: '删除成功',
            data: null
        }
    },
    getOrderData: (config) => {
        var { key,page,pagesize } = param2Obj(config.url)
        console.log(config);
        console.log(key,page, pagesize);

        var newList = List.filter(item =>
            item.weixin.toString().indexOf(key) != -1 ||
            item.tel.regexp.indexOf(key) != -1
        )
        // 对搜索的结果做分页
        // pagesize
        var pageResult = newList.filter((item, index) => {
            return (page - 1) * pagesize <= index && index < page * pagesize
        })
        return {
            code: 200,
            msg: '请求成功',
            data: pageResult,
            total: List.length
        }
    },

    getCaseData: (config) => {
        // console.log(config);
        var {
            choice
        } = param2Obj(config.url)
        console.log(choice);
        var newList = List.filter(item => {
            return choice == 1 ? item : item.type == choice
        })
        return {
            code: 200,
            msg: '请求成功',
            data: newList
        }
    },

    getTimeData: (config) => {
        var {
            time1,
            time2
        } = param2Obj(config.url)
        console.log(time1, time2);
        return {
            code: 200,
            msg: '请求成功',
            data: null
        }
    },


}